package com.lswms.modules.lswms.dao.receipt;

import java.util.List;
import java.util.Map;

import com.lswms.modules.lswms.dto.receipt.ReceiptdetaillistDTO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.lswms.common.dao.BaseDao;
import com.lswms.modules.lswms.entity.receipt.ReceiptdetaillistEntity;
import com.lswms.modules.lswms.entity.stock.InventoryEntity;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * 收货明细记录
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-06-13
 */
@Mapper
public interface ReceiptdetaillistDao extends BaseDao<ReceiptdetaillistEntity> {
	 public Integer getReceiptdetaillistMaxLine(@Param("receiptkey") String receiptkey  ,@Param("line") Integer line   ) ;

	public List<InventoryEntity> getPutawayList(@Param("receiptkey")String receiptkey);

	public List<InventoryEntity> getFirstInventory(@Param("tray")String tray);

	public Integer getReceiptAndInventory(@Param("receiptkey")String receiptkey, @Param("line")Integer line, @Param("linelist")Integer linelist);

	public Integer hasCreatePutaway(@Param("receiptkey")String receiptkey);

	void revoke();

	 @Select(value ="select lswms_receiptdetaillist.* ,b.listname statusstr ,c.listname  boxstr ,d.descr , d.factorycdoe factorycdoe "
	 		+ "from lswms_receiptdetaillist left  join lswms_codelist b  on lswms_receiptdetaillist.status = b.list and b.code='receiptstatus' "
	 		+ "		left  join lswms_codelist c  on lswms_receiptdetaillist.tobox = c.list and c.code='BOXLIST' "
	 		+ "		left  join lswms_sku d  on lswms_receiptdetaillist.sku = d.sku  ${ew.customSqlSegment}")
	public IPage<ReceiptdetaillistEntity> selectPageBySql(IPage<ReceiptdetaillistEntity> page,
			@Param(Constants.WRAPPER)QueryWrapper<ReceiptdetaillistEntity> wrapper);

	 @Select(value ="select lswms_receiptdetaillist.* ,b.listname statusstr ,c.listname  boxstr ,d.descr , d.factorycdoe factorycdoe "
		 		+ "from lswms_receiptdetaillist left  join lswms_codelist b  on lswms_receiptdetaillist.status = b.list and b.code='receiptstatus' "
		 		+ "		left  join lswms_codelist c  on lswms_receiptdetaillist.tobox = c.list and c.code='BOXLIST' "
		 		+ "		left  join lswms_sku d  on lswms_receiptdetaillist.sku = d.sku  ${ew.customSqlSegment}")
	 public List<ReceiptdetaillistEntity> listBySql(@Param(Constants.WRAPPER)Map<String, Object> params);
	 
	 
	 @Select("<script> select a.sku,b.descr, b.factorycdoe factorycdoe,a.totray, a.lot6,a.lot8,a.lot11,a.lot12,a.lot13,sum(a.actqty) qty\n"
	 		+ " from lswms_receiptdetaillist a,lswms_sku b\n"
	 		+ " where a.sku = b.sku  and a.actqty>0\n"
	 		+ "	 and "
	 		+ "<foreach item=\"item\" collection=\"list\" separator=\" )or( \" open=\"((\" close=\"))\" index=\"\">\n"
	 		+ "    <if test=\"item.receiptkey != null and item.receiptkey !='' \" >"
	 		+ "   a.receiptkey =#{item.receiptkey} " 
	 		+ "		</if>  "
	 		+ "    <if test=\"item.line != null and item.line !='' \" >"
	 		+ "  and  a.line =#{item.line} " 
	 		+ "		</if> "
	 		+ " </foreach>"
	 		+ " group by a.sku,b.descr, b.factorycdoe ,factorycdoe,a.totray, a.lot6,a.lot8,a.lot11,a.lot12,a.lot13"
	 		+ "</script>")
	 public List<Map<String, Object>> getPrintQc( List list);

	

	 /*@Select("select lot from lswms_receiptdetaillist where toloc=#{location} and sku=#{sku} and totray={tray} and receiptkey=#{receiptkey} and tobox=#{box}")
	 String getLot(@Param("receiptkey")String receiptkey,@Param("tray")String tray,@Param("box")String box,@Param("location")String location,@Param("sku")String sku);*/

}
